Derive macro for defining storable documents
This derive macro helps to define documents which can be managed using persistent storages like LEDB.
The LEDB is an attempt to implement simple but efficient, lightweight but powerful document storage.
The abbreviation LEDB may be treated as an Lightweight Embedded DB, also Low End DB, also Literium Engine DB, also LitE DB, and so on.
Links
Usage example
use serde::{Serialize, Deserialize};
use ledb::{Document};
#[derive(Serialize, Deserialize, Document)]
struct MyDoc {
#[document(primary)]
id: Option<Primary>,
#[document(unique)]
title: String,
#[document(index)]
tag: Vec<String>,
#[document(unique)]
timestamp: u32,
#[document(nested)]
meta: MetaData,
}
#[derive(Serialize, Deserialize, Document)]
#[document(nested)]
struct MetaData {
#[document(index)]
keywords: Vec<String>,
description: String,
}
This automatically generate Document
traits like so:
impl Document for MyDoc {
fn primary_field() -> Identifier {
"id".into()
}
fn key_fields() -> KeyFields {
KeyFields::new()
.with_field(("title", String::key_type(), IndexKind::Unique))
.with_field(("tag", String::key_type(), IndexKind::Index))
.with_field(("timestamp", u32::key_type(), IndexKind::Unique))
.with_fields(MetaData::key_fields().with_parent("meta"))
}
}
impl Document for MetaData {
fn key_fields() -> KeyFields {
KeyFields::new()
.with_field(("keywords", KeyType::String, IndexKind::Index))
}
}